import type { SecurityItem, UserData } from '~/types/user'

export const createSecurityItems = (userData: UserData | undefined): SecurityItem[] => [
  {
    title: '手机账号',
    label: userData?.userPhone || '未绑定手机号',
    button: userData?.userPhone ? '更换手机' : '绑定手机',
    action: 'phone',
    showStatus: true,
    verified: !!userData?.userPhone
  },
  {
    title: '实名认证',
    label: userData?.idCard ? '已完成实名认证' : '未实名认证',
    button: '立即认证',
    action: 'identity',
    showStatus: true,
    verified: !!userData?.idCard
  },
  {
    title: '支付宝绑定',
    label: userData?.alipayPhone ? '已绑定' : '未绑定',
    button: userData?.alipayPhone ? '更换绑定' : '立即绑定',
    action: 'alipay',
    showStatus: true,
    verified: !!userData?.alipayPhone
  },
  {
    title: '密码设置',
    label: '建议定期更换密码，提高账号安全性',
    button: '修改密码',
    action: 'password',
    showStatus: false,
    verified: true
  },
  {
    title: '一键绑定Steam',
    label: userData?.steamId ?
      `已绑定 - Steam ID: ${userData.steamId}${userData.apiKey ? ' | API Key已设置' : ''}${userData.transactionLink ? ' | 交易链接已设置' : ''}` :
      '未绑定',
    // 只有当steamId、apiKey和tradeUrl都存在时才显示"一键解绑"
    button: (userData?.steamId && userData?.apiKey && userData?.tradeUrl) ? '一键解绑' : '一键绑定',
    action: 'Bindsteam',
    showStatus: false,
    // 同样，验证状态也需要三个条件都满足
    verified: !!(userData?.steamId && userData?.apiKey && userData?.tradeUrl)
  },
  {
    title: 'Steam ID',
    label: userData?.steamId || '未绑定',
    button: userData?.steamId ? '解绑' : '绑定',
    action: 'steam',
    showStatus: false,
    verified: !!userData?.steamId
  },
  {
    title: 'API key',
    label: userData?.apiKey ? '************************' : '未设置',
    button: '保存',
    action: 'apikey',
    showStatus: false,
    verified: !!userData?.apiKey
  },
  {
    title: '交易链接',
    label: userData?.tradeUrl || 'https://steamcommunity.com/tradeoffer/new/',
    button: '保存',
    action: 'tradeurl',
    showStatus: false,
    verified: !!userData?.tradeUrl
  }
]